var ns, app;
app = new Vue({
    el: '#app',
    data: {
        list:[],
        type:1,
        ID:0,
        ServiceType:1,
        source:'transfer',
    },
    methods: {
        guanbi_pic:function(id){
            var that=this;
            that.list = that.list.filter((item) => {
                return item.UserID != id
                });
            api.sendEvent({
                name:'purchase_update',
                extra: {
                    data: that.list,
                    type:that.type
                }
            })
        },
        choose_persons:function(){
            var that=this;
            ns.openWin('chooseserviceuser_frm', '选择接单人员', {
                source: that.source,
                id: that.ID,
                type: that.type,
                ServiceType: that.ServiceType,
            });  
        },
    }
});
apiready = function () {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.list = api.pageParam.list;
    app.type = api.pageParam.type;
    app.ID = api.pageParam.id||0;
    app.source = api.pageParam.source||'transfer';
    app.ServiceType = api.pageParam.ServiceType||1;

    api.addEventListener({
        name:'purchase_add'
    }, function(ret){
        for (var i = 0; i < ret.value.data.length; i++) {
            var item = ret.value.data[i];
            item.UserID = item.userID;
            item.UserName = item.realName;
            app.list.push(item);
        }
        let obj = {};
        let peon = app.list.reduce((cur,next) => {
            obj[next.UserID] ? "" : obj[next.UserID] = true && cur.push(next);
            return cur;
        },[]) ;
        app.list=peon;
    })
};
